<?php

namespace  App\Http\Controllers\V1;

use App\Events\V1\UserCountChannelEvent;
use App\Events\V1\UserRegEvent;
use App\Helpers\DateUtils;
use App\Helpers\RestResponseFactory;
use App\Helpers\RestUtils;
use App\Helpers\Utils;
use App\Http\Controllers\Controller;
use App\Models\Factory\ComDeviceFactory;
use App\Models\Factory\SmsFactory;
use App\Models\Factory\UserFactory;
use App\Models\Factory\UserInviteCodeFactory;
use Illuminate\Http\Request;


/**
 * 快捷登录
 * Class QuickController
 * @package App\Http\Controllers\V1
 */
class QuickController extends  Controller
{

    /**
     * 快速登录
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function login(Request $request)
    {
        //接收参数
        $data = $request->input();

////        检查验证码是否正确
//        $re = SmsFactory::getSmsRandomFromCache($data['userphone'].'_item_code');
//        if (!($re == $data['code']))
//        {
//            return RestResponseFactory::ok(RestUtils::getStdObj(), RestUtils::getErrorMessage(1204), 1204);
//        }



        //生成该用户的唯一标识token并保存到数据库
        $user = UserFactory::getUserByMobile($data['userphone']);

		//根据用户的主键生成token
        $token['token'] = md5("anwen".time().$user['id']);
        $token['lass_time'] = DateUtils::getToday();
        //把用户的唯一标识保存到数据库内
        UserFactory::addUserTokenByMobile($data['userphone'],$token);
////
//        if($result)
//        {
            return RestResponseFactory::ok($token,200);

//        }

        return RestResponseFactory::ok(RestUtils::getStdObj(), RestUtils::getErrorMessage(1101), 1101);

    }
}
